package com.cskaoyan.jdbc;

// 驱动程序包
import com.mysql.jdbc.Driver;


// JDBC
import java.sql.*;

/**
 * 创建日期: 2022/06/01 10:25
 *
 * @author ciggar
 */
public class FirstDemo {
    static String url = "jdbc:mysql://localhost:3306/41th?useSSL=false&characterEncoding=utf8";
    static String username = "root";
    static String password = "123456";
    static String driver = "com.mysql.jdbc.Driver";

    public static void main(String[] args) throws SQLException, ClassNotFoundException {

        // 1. 注册驱动  // 传入的是驱动包里面的Driver接口的实现
//        DriverManager.registerDriver(new Driver());
//        new Driver();
        Class.forName(driver);

        // 2. 建立连接 JDBC4Connection
        Connection connection = DriverManager.getConnection(url,username,password);

        // 3. 获取Statement对象  StatementImpl
        Statement statement = connection.createStatement();

        // 4. 发送SQL语句
        // 执行查询语句
        // statement.executeQuery();

        // 执行增删改语句
        int affectedRows = statement.executeUpdate("update city set name = '南京' where id = 1002");
        ResultSet resultSet = null;

        // 5. 解析结果集
        System.out.println("affectedRows:" + affectedRows);

        //6. 断开连接
        statement.close();
        connection.close();

    }
}
